home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 425_01 / tar / tar.c < prev    next >
Text File  |  1994-04-02  |  35KB  |  1,054 lines

  1. /* tar.c - Tape ARchive utility program (main function)
  2.  * Author: T.V.Shaporev
  3.  * Creation date: 14 Dec 1990
  4.  *
  5.  * The program works in a same fashion under UNIX (most clones) and MS-DOS.
  6.  * The main idear was to develop a tool for file transferring via diskette
  7.  * between different operating systems - such as all UNIX clones, MS-DOS,
  8.  * RSX, VAX/VMS - and all others which support tar format on a diskette.
  9.  *
  10.  * First step on this way (made in 1989) lies in adapting common UNIX tar
  11.  * program to MS-DOS.
  12.  *
  13.  * On the second step
  14.  *  - some bugs were fixed (especially in DOS-applied codes) and some
  15.  *    optimization were done;
  16.  *  - nonstandard (under DOS) diskette formats were added (i.e.
  17.  *    DEC Rainbow and 80 tracks & 9 sectors format)
  18.  *  - the possibility for compress encoding were included
  19.  *    (this compressor has the best ratio among all others which
  20.  *    I know, but don't ask me about its speed). Compressed-file
  21.  *    format is compatible with the common versions of tar, so You
  22.  *    can extract the compressed image from the archive by the
  23.  *    common program, but I doubt You could uncompress them at last.
  24.  *
  25.  * On the fird step the program was totally (newly) overwritten to bypass
  26.  * any copyright exclamations. In fact, it must be considered new program
  27.  * but I prefer to continue version enumeration (I hope, nobody cares).
  28.  *
  29.  * I think, this program must be called Tar (with capital first letter)
  30.  * to distinguish it from regular UNIX tar.
  31.  *
  32.  * The program's behaviour is analogous to usual tar, and I hope, its
  33.  * internal help will be enough to understand the differences.
  34.  *
  35.  * The program doesn't perform any text file conversion - it passes
  36.  * strict binary image of each file. If You has a problems with reading
  37.  * DOS text files under UNIX (or UNIX files under DOS) please use my
  38.  * dostext program.
  39.  *
  40.  * The program must be compiled by Turbo C 2.0 compiler (in a compact
  41.  * model) under MS-DOS. Please don't replace dynamic arrays back to
  42.  * static and automatic - MS-DOS compilers dislike them.
  43.  *
  44.  *            tim    tim@ecsc.mipt.su    14 Dec 1990
  45.  */
  46. /* Version 3.01
  47.  * Handling of the 'l' option corrected
  48.  */
  49. /* Version 3.02                                       31 Dec 1990
  50.  *  - great deal of minor corrections
  51.  *  - u<pdate> option expanded to extracting
  52.  *  - j<ournal> option added (comment storying files)
  53.  *  - wildcards * and ? are now processed in archive; this may be
  54.  *    suppressed by s<trict> option
  55.  *  - d<elete> option added to replace previous occurencies of files
  56.  *    in archive on storying, or deleting files from archive when
  57.  *    whithout a<dd> parameter - this is for file archives only!
  58.  */
  59. /* Version 3.03                                       22 Feb 1991
  60.  *  - an error corrected in mismatch() (file extract.c)
  61.  *  - decreased stack requirements for tree processing
  62.  *    (see store() in store.c and putfiles() in tar.c)
  63.  *  - added codes to prevent archive file self-storying
  64.  *    (not quite reliable for MS-DOS)
  65.  *  - bincall() invocations changed by calls to rmdir() and mkdir()
  66.  *    this is done automatically for 386/ix and may be switched by
  67.  *    RMKDIR macro
  68.  */
  69. /* Version 3.04                                       29 Jul 1991
  70.  *  - a direct intialization of static global variables inserted into
  71.  *    lzencode() and lzdecode() - see file lzpack.c
  72.  */
  73. /* Version 3.04b                                      03 Oct 1991
  74.  *  - a minor correction of bincall()
  75.  *  - added default block number = sectors on track (MS-DOS)
  76.  */
  77. /* Version 3.05                                       11 Nov 1991
  78.  *  - block factor for diskette writing is set to 1 for most BIOS
  79.  *    compatibility
  80.  *  - scantape() is slightly optimized
  81.  */
  82. /* Version 3.06                                       17 Dec 1991
  83.  *  - n<onest> option applied to all actions (see inarg() in extract.c)
  84.  *  - command-line-extension-file option (responce file) added
  85.  *    for vak (vak@kiae.su) request (see append() in tar.c)
  86.  *  - p<ermission> option added to save directories permissions (UNIX)
  87.  */
  88. /* Version 3.06b                                      22 Dec 1991
  89.  *   - UNIX to DOS renaming algorithm (dot elimination) slightly
  90.  *     changed (see extract.c)
  91.  *   - most of output redirected to stdout (vs stderr)
  92.  */
  93. /* Version 3.07                                       28 Dec 1992
  94.  *   - all unary apostrofs in string constants preserved by backslashes
  95.  *   - reading file list from stdin allowed (see append() in tar.c)
  96.  *   - input redirected to /dev/tty under UNIX
  97.  *   - support for traditional UNIX compression algorithm
  98.  *   - few changes in converting UNIX names for DOS
  99.  */
  100. /* Version 3.07b                                      20 Jan 1993
  101.  *   - gethead() does not return FALSE while errors,
  102.  *     scantape() looks for tape reading errors
  103.  */
  104. /* Version 3.08                                       22 Feb 1993
  105.  *   - method-dependent comression indicator masks (see percent.c)
  106.  *   - 'z' option applied to catalog printing (see catalog())
  107.  *   - compatibility corrections in directory structure checking
  108.  *   - st.st_size == codesize - means file unpacked! (see extract.c)
  109.  */
  110. /* Version 3.09                                       14 Mar 1993
  111.  *   - a bug fixed wich prevents archiving unpacked files at all
  112.  *     (ha-ha!) - see store.c
  113.  *   - changed header description to support new features
  114.  *     see define.h
  115.  *   - support for P1003 and GNU file types - 't' option only! -
  116.  *     see extract.c
  117.  *   - small changes in #ifdef-s to distinguish SCO UNIXes from
  118.  *     XENIXes - see store.c
  119.  *   - regular file processing extracted into separate source
  120.  *     files (see savefile.c & restore.c)
  121.  *   - support for devices and FIFOs added
  122.  *   - 'l' option added for DOS (copy linked files)
  123.  *   - support for System V extents - see extract.c and restore.c
  124.  *     to read archives only, extents may not be unpacked on the
  125.  *     fly - alas, that's all for now
  126.  *   - an error corrected in roll.c
  127.  */
  128. /* Version 3.10                                       28 Jun 1993
  129.  *   - a bug fixed in old compression code (see lzpack.c)
  130.  *   - added possibility to run through compress (',' comma option)
  131.  *     see tar.c, tape.c and compress.c
  132.  *   - comments will not be printed unless 'j' is given (extract.c)
  133.  *   - separated compress-related codes
  134.  */
  135. /* Version 3.11                                       14 Jul 1993
  136.  *   - support for QIC-02 streamers (first version!)
  137.  *     devices supported: fastape, everex
  138.  */
  139. /* Version 3.12                                       29 Sen 1993
  140.  *   - slack area in archive is filled by nulls to improve compression
  141.  *   - added support for Wangtek (QIC-02) device
  142.  *   - a bug fixed in memory release ('pk_out' variable - see _done())
  143.  *   - program support for QIC-02 drive number and tape format
  144.  *     selection
  145.  *   - experimental (!) support for appending QIC-02 tapes
  146.  *     (see qback() in qicface.c)
  147.  *   - LZW support splitted into compressor and extractor and
  148.  *     the letter included in official release (see unlzw.c etc.)
  149.  *   - get default file name from TAPE environment variable
  150.  *   - 'o' flag for DOS means prevent file overwriting
  151.  */
  152. /* Version 3.12b                                      10 Nov 1993
  153.  *   - an error corrected in QIC device selection (see qicface.c)
  154.  *   - eliminated idle rewindings around QIC tape initialisation
  155.  */
  156. /* Version 3.13                                       26 Dec 1993
  157.  *   - online inflatter (unzip) and corresponding '.' (point) option
  158.  */
  159. /* Version 3.14                                       19 Feb 1994
  160.  *   - online deflatter (zip); compilation model changed to large
  161.  */
  162. /* Version 3.15 - general bugfix                      03 Apr 1994
  163.  *   - strerror() missed in some UNIXes, so psyserr() function added
  164.  *     into tape.c
  165.  *   - extended local header signature inserted in deflated output and
  166.  *     unzclose() changed to uderstand both formats
  167.  *     (see zipdefs.h, zippipe.c and diszip.c)
  168.  *   - pkflush() output is aligned to pksize boundary if output is not
  169.  *     regula